module.exports = (sequelize, DataTypes) => {
    return sequelize.define(
        'Department',
        {
            id: {
                type: DataTypes.BIGINT.UNSIGNED,
                allowNull: false,
                autoIncrement: true,
                primaryKey: true
            },
            name: {
                type: DataTypes.STRING(20),
                allowNull: false,
                validate: {
                    notNull: {
                        msg: '部门名不能为空'
                    }
                },
                comment: '部门名'
            },
            parent_id: {
                type: DataTypes.BIGINT.UNSIGNED,
                references: {
                    model: 'Department',
                    key: 'id'
                },
                comment: '父级ID'
            }
        },
        {
            tableName: 'department'
        }
    )
}
